package com.feihao.zhou.UDP.demo02MutiTest;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;

public class ReceiveDemo {
    public static void main(String[] args) throws IOException {
        MulticastSocket ms = new MulticastSocket(10022);

        //创建箱子接收：
        DatagramPacket dp = new DatagramPacket(new byte[1024], 1024);

        //加入组：
        ms.joinGroup(InetAddress.getByName("224.0.1.0"));

        //接收到箱子：
        ms.receive(dp);

        //解析数据：
        byte[] data = dp.getData();
        int length = data.length;
        System.out.println(new String(data, 0, length));

        ms.close();
    }
}
